package com.jingdianjichi.subject.domain.handler.subject;

import com.google.common.base.Preconditions;
import com.jingdianjichi.subject.common.enums.IsDeletedFlageEnum;
import com.jingdianjichi.subject.common.enums.SubjectInfoTypeEnum;
import com.jingdianjichi.subject.domain.convert.BriefSubjectConverter;
import com.jingdianjichi.subject.domain.convert.JudgeSubjectConverter;
import com.jingdianjichi.subject.domain.entity.SubjectInfoBo;
import com.jingdianjichi.subject.domain.entity.SubjectOptionBo;
import com.jingdianjichi.subject.infra.basic.entity.SubjectBrief;
import com.jingdianjichi.subject.infra.basic.entity.SubjectJudge;
import com.jingdianjichi.subject.infra.basic.service.SubjectBriefService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.LinkedList;
import java.util.List;

/**
 * 简答题目的策略类
 */
@Component
public class BriefTypeHandler implements SubjectTypeHandler {
    @Resource
    private SubjectBriefService subjectBriefService;

    @Override
    public SubjectInfoTypeEnum getHandlerType() {
        return SubjectInfoTypeEnum.BRIEF;
    }

    @Override
    public void add(SubjectInfoBo subjectInfoBo) {
        //简答题目的插入

//        List<SubjectBrief> subjectBriefList = new LinkedList<>();
//        subjectInfoBo.getOptionList().forEach(option -> {
//            SubjectBrief subjectBrief = BriefSubjectConverter.INSTANCE
//                    .convertBoToEntity(option);
        SubjectBrief subjectBrief = new SubjectBrief();
        subjectBrief.setSubjectId(subjectInfoBo.getId());
        subjectBrief.setSubjectAnswer(subjectInfoBo.getSubjectAnswer());
        subjectBrief.setIsDeleted(IsDeletedFlageEnum.UN_DELETE.getCode());
//            subjectBriefList.add(subjectBrief);
//        });
        subjectBriefService.insert(subjectBrief);
    }

    @Override
    public SubjectOptionBo queue(Long subjectId) {
        SubjectBrief subjectBrief = new SubjectBrief();
        subjectBrief.setSubjectId(subjectId);
        SubjectBrief result = subjectBriefService.queryByCondition(subjectBrief);
        SubjectOptionBo subjectOptionBo = new SubjectOptionBo();
        subjectOptionBo.setSubjectAnswer(result.getSubjectAnswer());
        return subjectOptionBo;
    }


}
